package com.dstz.demo.rest.controller;

import com.dstz.base.api.aop.annotion.CatchErr;
import com.dstz.base.api.query.QueryFilter;
import com.dstz.base.api.response.impl.ResultMsg;
import com.dstz.base.rest.BaseController;
import com.dstz.demo.core.manager.PCompanyFinancialSituationManager;
import com.dstz.demo.core.model.PCompanyFinancialSituation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;


/**
 * 财务状况表 控制器类<br/>
 * @author  aschs
 * </pre>
 */
@RestController
@RequestMapping("/sys/pCompanyFinancialSituation")
public class PCompanyFinancialSituationController extends BaseController<PCompanyFinancialSituation>{
	@Resource
	PCompanyFinancialSituationManager pCompanyFinancialSituationManager;
	
	
	@Override
	protected String getModelDesc() {
		return "财务状况表";
	}
	@PostMapping("/insert")
	@CatchErr("添加失败")
	public ResultMsg insertPCompanyQualification(@RequestBody PCompanyFinancialSituation pCompanyFinancialSituation){
		QueryFilter queryFilte=getQueryFilter(null);
		queryFilte.addParamsFilter("p_company_id",pCompanyFinancialSituation.getPCompanyId());
		List<PCompanyFinancialSituation> selectPCompanyQualification=pCompanyFinancialSituationManager.selectPCompanyFinancialSituation(queryFilte);
		if (selectPCompanyQualification.size()<=0){
			pCompanyFinancialSituation.setFinancialSituationId(UUID.randomUUID().toString());
			pCompanyFinancialSituationManager.insertPCompanyFinancialSituation(pCompanyFinancialSituation);
		}else {
			pCompanyFinancialSituation.setFinancialSituationId(selectPCompanyQualification.get(0).getFinancialSituationId());
			pCompanyFinancialSituationManager.updatePCompanyFinancialSituation(pCompanyFinancialSituation);
		}
		return getSuccessResult("添加成功");
	}

	@PostMapping("/update")
	@CatchErr("修改失败")
	public ResultMsg updatePCompanyQualification(@RequestBody PCompanyFinancialSituation pCompanyFinancialSituation){
		pCompanyFinancialSituationManager.updatePCompanyFinancialSituation(pCompanyFinancialSituation);
		return getSuccessResult("修改成功");
	}
}
